use image::{GenericImageView, imageops};

fn main() {
    // 加载图片
    let mut img = image::open("input.jpg").unwrap();

    // 获取原始图片的宽度和高度
    let (width, height) = img.dimensions();

    // 计算水平和垂直方向上切割的块数
    let num_chunks_horizontal = 3;
    let num_chunks_vertical = 1;

    // 计算每个切割区域的宽度和高度
    let chunk_width = width / num_chunks_horizontal;
    let chunk_height = height / num_chunks_vertical;

    // 遍历每个切割区域并保存为新图片
    for i in 0..num_chunks_horizontal {
        for j in 0..num_chunks_vertical {
            // 计算当前切割区域的左上角坐标
            let x = i * chunk_width;
            let y = j * chunk_height;

            // 切割图片
            let chunk = imageops::crop(&mut img, x, y, chunk_width, chunk_height).to_image();

            // 保存切割后的图片
            chunk.save(format!("output/chunk_{}_{}.jpg", i, j)).unwrap();
        }
    }
}
